Hi guys, I want to create a DXL script that recursively creates in DOORS a folder structure replicated after a Windows folder structure with an inputted Windows path, for ex: "C:\\test\\another_folder\\subfolder\\etc". |
Re: Script that replicates folder structure
You do not want to "delete" the "." and ".." files.
are suspicious and I would test them somehow.
//*****************************************************************
void SearchDir(string NameDir, bool Recurse, Buffer &bufResults)
{ // display the folders and files in the directory
// Optionally Recurs through subfolders
// This function is RECURSION enabled
string NameFile
string NameFull
Stat stat
set (dbeStatus, "... '" NameDir "'")
g_NumFolders++
bufResults += "\n..." NameDir[g_OriginLen:]"\n"
// *** [1] Print the info of all SubFolders
for NameFile in directory NameDir do
{ if (NameFile[0:0] == ".") // skip the "." and ".." file names. No other name may begin with '.'
continue
if (NameFile == NameDir) // Don't recall why, but skip a file with exact name as Directory
{ print ">>SearchDir, NameFile == NameDir '" NameFile "'\n"
continue
}
NameFull = NameDir "\\" NameFile
stat = create(NameFull)
// print "considering >" NameFull "<\n"
if (!null stat and directory(stat))
DisplayFileInfo(stat, true, NameDir, NameFile, bufResults)
if (!null stat) delete(stat)
}
// *** [2] Print the info of all Files
for NameFile in directory NameDir do
{ if (NameFile[0:0] == ".")
continue
if (NameFile == NameDir)
continue
g_NumFiles++
NameFull = NameDir "\\" NameFile
stat = create(NameFull)
if (!null stat and (regular(stat) or symbolic(stat)))
DisplayFileInfo(stat, false, NameDir, NameFile, bufResults)
if (!null stat) delete(stat)
}
// *** [3] Recurs through SubFolders
if (Recurse)
{ for NameFile in directory NameDir do
{ if (NameFile[0:0] == ".")
continue
NameFull = NameDir "\\" NameFile
stat = create(NameFull)
if (!null stat and directory(stat))
{ // print "*** NOT Doing >" NameFull "<\n"
SearchDir(NameFull, Recurse, bufResults) // ** RECURSION **
}
if (!null stat) delete(stat)
}
}
} // end SearchDir()
|
Re: Script that replicates folder structure llandale - Tue Apr 02 10:31:27 EDT 2013
You do not want to "delete" the "." and ".." files.
are suspicious and I would test them somehow.
//*****************************************************************
void SearchDir(string NameDir, bool Recurse, Buffer &bufResults)
{ // display the folders and files in the directory
// Optionally Recurs through subfolders
// This function is RECURSION enabled
string NameFile
string NameFull
Stat stat
set (dbeStatus, "... '" NameDir "'")
g_NumFolders++
bufResults += "\n..." NameDir[g_OriginLen:]"\n"
// *** [1] Print the info of all SubFolders
for NameFile in directory NameDir do
{ if (NameFile[0:0] == ".") // skip the "." and ".." file names. No other name may begin with '.'
continue
if (NameFile == NameDir) // Don't recall why, but skip a file with exact name as Directory
{ print ">>SearchDir, NameFile == NameDir '" NameFile "'\n"
continue
}
NameFull = NameDir "\\" NameFile
stat = create(NameFull)
// print "considering >" NameFull "<\n"
if (!null stat and directory(stat))
DisplayFileInfo(stat, true, NameDir, NameFile, bufResults)
if (!null stat) delete(stat)
}
// *** [2] Print the info of all Files
for NameFile in directory NameDir do
{ if (NameFile[0:0] == ".")
continue
if (NameFile == NameDir)
continue
g_NumFiles++
NameFull = NameDir "\\" NameFile
stat = create(NameFull)
if (!null stat and (regular(stat) or symbolic(stat)))
DisplayFileInfo(stat, false, NameDir, NameFile, bufResults)
if (!null stat) delete(stat)
}
// *** [3] Recurs through SubFolders
if (Recurse)
{ for NameFile in directory NameDir do
{ if (NameFile[0:0] == ".")
continue
NameFull = NameDir "\\" NameFile
stat = create(NameFull)
if (!null stat and directory(stat))
{ // print "*** NOT Doing >" NameFull "<\n"
SearchDir(NameFull, Recurse, bufResults) // ** RECURSION **
}
if (!null stat) delete(stat)
}
}
} // end SearchDir()
Try this.
// Create Doors Folder Structure from Windows Directory Structure
/*
...or create Doors from Windows!
Tony Goodman
*/
pragma runLim, 0
DB dbMain = null
DBE dbeRootDoorsFolder = null
DBE dbeRootWindowsDirectory = null
DBE dbeBrowseDoors = null
DBE dbeBrowseWindows = null
/*******************
getWindowsFolder
********************/
string getWindowsFolder(string &dirPath)
{
OleAutoObj objDialog = null
OleAutoObj objFolder = null
OleAutoObj objFolderItem = null
OleAutoArgs args = create
string folderPath = ""
string res = ""
dirPath = ""
objDialog = oleCreateAutoObject("Shell.Application")
if (null objDialog)
{
return("Failed to create dialog object")
}
put(args, 0) // always zero
put(args, "Please select a folder") // title
put(args, 0) // options
res = oleMethod(objDialog, "BrowseForFolder", args, objFolder)
if (null objFolder)
{
if (res "" != "")
{
return("Failed to launch browser: " res)
}
else
{
return("")
}
}
res = oleGet(objFolder, "Self", objFolderItem)
if (null objFolderItem)
{
return("Failed to get folder item: " res)
}
oleGet(objFolderItem, "Path", folderPath)
dirPath = folderPath
return(res)
}
/*********************
isDirectory
Returns TRUE if string parameter is a valid windows directory.
*********************/
bool isDirectory(string dn)
{
Stat s = create dn
if (null s) return false
if (directory s)
{
delete s
return true
}
delete s
return false
}
/**************************
getShortName
**************************/
string getShortName(string dir)
{
string shortName = ""
int i = 0
for (i = length(dir) - 1; i > 0; i--)
{
if (dir[i:i] == "\\")
break
}
if (i > 0)
{
shortName = dir[i+1:]
}
return(shortName)
}
/**************************
createFoldersFromDirectories
**************************/
void createFoldersFromDirectories(string doorsFolder, string windowsDirectory)
{
string res = ""
string f = ""
string shortName = ""
Folder newFolder = null
(current FolderRef__) = folder(doorsFolder)
shortName = getShortName(windowsDirectory)
if (shortName == "")
{
infoBox("Invalid directory name: " windowsDirectory)
return
}
// create DOORS folder
res = create(shortName, "", newFolder)
if (res "" != "")
{
infoBox(res)
return
}
for f in directory windowsDirectory do
{
// ignore this directory and parent
if (f == "." || f == "..") continue
if (isDirectory(windowsDirectory "\\" f))
{
createFoldersFromDirectories(fullName(newFolder), windowsDirectory "\\" f)
}
}
}
/**************************
doBrowseWindows
**************************/
void doBrowseWindows(DBE dbe)
{
string res = ""
string dirName = ""
res = getWindowsFolder(dirName)
if (res == "")
{
set(dbeRootWindowsDirectory, dirName)
}
else
{
infoBox(res)
}
}
/******************************************************************************
doBrowseDoors
******************************************************************************/
void doBrowseDoors(DBE dbe)
{
string szFolderName = fnMiniExplorer(dbMain, (current Folder), MINI_EXP_FP, "Select Folder", "Select Folder")
// ensure that mini explorer has returned a valid module name
if (szFolderName != "" && folder(szFolderName))
{
set(dbeRootDoorsFolder, szFolderName )
}
}
/**********************
doOK
***********************/
void doOK(DB db)
{
string rootWindows = ""
string rootDoors = ""
rootDoors = get(dbeRootDoorsFolder)
rootWindows = get(dbeRootWindowsDirectory)
if (!confirm("You are about to create a new folder structure.\nAre you sure you want to continue?"))
{
return
}
createFoldersFromDirectories(rootDoors, rootWindows)
refreshDBExplorer()
}
/*********************
MAIN
**********************/
dbMain = create("Create Folder Structure", styleCentered)
label(dbMain, "This utility will create a new folder structure in DOORS " //-
"that reflects the structure of the selected windows directory.\n")
dbeRootDoorsFolder = field(dbMain, "Current Folder:", fullName(current Folder), 60, false)
beside(dbMain)
dbeBrowseDoors = button(dbMain, "Browse...", doBrowseDoors)
left(dbMain)
dbeRootWindowsDirectory = field(dbMain, "Windows Directory:", "", 60, false)
beside(dbMain)
dbeBrowseWindows = button(dbMain, "Browse...", doBrowseWindows)
ok(dbMain, doOK)
realize dbMain
show(dbMain)
|
Re: Script that replicates folder structure Tony_Goodman - Wed Apr 03 05:44:52 EDT 2013 Try this.
// Create Doors Folder Structure from Windows Directory Structure
/*
...or create Doors from Windows!
Tony Goodman
*/
pragma runLim, 0
DB dbMain = null
DBE dbeRootDoorsFolder = null
DBE dbeRootWindowsDirectory = null
DBE dbeBrowseDoors = null
DBE dbeBrowseWindows = null
/*******************
getWindowsFolder
********************/
string getWindowsFolder(string &dirPath)
{
OleAutoObj objDialog = null
OleAutoObj objFolder = null
OleAutoObj objFolderItem = null
OleAutoArgs args = create
string folderPath = ""
string res = ""
dirPath = ""
objDialog = oleCreateAutoObject("Shell.Application")
if (null objDialog)
{
return("Failed to create dialog object")
}
put(args, 0) // always zero
put(args, "Please select a folder") // title
put(args, 0) // options
res = oleMethod(objDialog, "BrowseForFolder", args, objFolder)
if (null objFolder)
{
if (res "" != "")
{
return("Failed to launch browser: " res)
}
else
{
return("")
}
}
res = oleGet(objFolder, "Self", objFolderItem)
if (null objFolderItem)
{
return("Failed to get folder item: " res)
}
oleGet(objFolderItem, "Path", folderPath)
dirPath = folderPath
return(res)
}
/*********************
isDirectory
Returns TRUE if string parameter is a valid windows directory.
*********************/
bool isDirectory(string dn)
{
Stat s = create dn
if (null s) return false
if (directory s)
{
delete s
return true
}
delete s
return false
}
/**************************
getShortName
**************************/
string getShortName(string dir)
{
string shortName = ""
int i = 0
for (i = length(dir) - 1; i > 0; i--)
{
if (dir[i:i] == "\\")
break
}
if (i > 0)
{
shortName = dir[i+1:]
}
return(shortName)
}
/**************************
createFoldersFromDirectories
**************************/
void createFoldersFromDirectories(string doorsFolder, string windowsDirectory)
{
string res = ""
string f = ""
string shortName = ""
Folder newFolder = null
(current FolderRef__) = folder(doorsFolder)
shortName = getShortName(windowsDirectory)
if (shortName == "")
{
infoBox("Invalid directory name: " windowsDirectory)
return
}
// create DOORS folder
res = create(shortName, "", newFolder)
if (res "" != "")
{
infoBox(res)
return
}
for f in directory windowsDirectory do
{
// ignore this directory and parent
if (f == "." || f == "..") continue
if (isDirectory(windowsDirectory "\\" f))
{
createFoldersFromDirectories(fullName(newFolder), windowsDirectory "\\" f)
}
}
}
/**************************
doBrowseWindows
**************************/
void doBrowseWindows(DBE dbe)
{
string res = ""
string dirName = ""
res = getWindowsFolder(dirName)
if (res == "")
{
set(dbeRootWindowsDirectory, dirName)
}
else
{
infoBox(res)
}
}
/******************************************************************************
doBrowseDoors
******************************************************************************/
void doBrowseDoors(DBE dbe)
{
string szFolderName = fnMiniExplorer(dbMain, (current Folder), MINI_EXP_FP, "Select Folder", "Select Folder")
// ensure that mini explorer has returned a valid module name
if (szFolderName != "" && folder(szFolderName))
{
set(dbeRootDoorsFolder, szFolderName )
}
}
/**********************
doOK
***********************/
void doOK(DB db)
{
string rootWindows = ""
string rootDoors = ""
rootDoors = get(dbeRootDoorsFolder)
rootWindows = get(dbeRootWindowsDirectory)
if (!confirm("You are about to create a new folder structure.\nAre you sure you want to continue?"))
{
return
}
createFoldersFromDirectories(rootDoors, rootWindows)
refreshDBExplorer()
}
/*********************
MAIN
**********************/
dbMain = create("Create Folder Structure", styleCentered)
label(dbMain, "This utility will create a new folder structure in DOORS " //-
"that reflects the structure of the selected windows directory.\n")
dbeRootDoorsFolder = field(dbMain, "Current Folder:", fullName(current Folder), 60, false)
beside(dbMain)
dbeBrowseDoors = button(dbMain, "Browse...", doBrowseDoors)
left(dbMain)
dbeRootWindowsDirectory = field(dbMain, "Windows Directory:", "", 60, false)
beside(dbMain)
dbeBrowseWindows = button(dbMain, "Browse...", doBrowseWindows)
ok(dbMain, doOK)
realize dbMain
show(dbMain)
|